Function.prototype.myCall = function(ctx, ...args) {
    ctx = ctx === undefined || ctx === null ? globalThis : Object(ctx)
    const fn = this
    const key = Symbol('temp')
    Object.defineProperty(ctx, key, {
        enumerable: false,
        value: fn
    })
    const result = ctx[key](...args)
    delete ctx[key]
    return result
}


Function.prototype.myBind = function(ctx) {
    let args = [...arguments].slice(1)
    let fn = this
    return function A() {
        let restArgs = [...arguments]
        let allArgs = args.concat(restArgs)
        if (Object.getPrototypeOf(this) === A.prototype) {
            return new fn(...allArgs)
        } else {
            return fn.apply(ctx, allArgs)
        }
    }
}